 <!--验证码区域-->
<div class="form-group">
    <label>{{_('验证码')}}</label>
    <input name="code" type="text" v-model="email_code" id="email_code" class="form-control osr-input"
           minlength="4" placeholder="{{_('邮箱验证码')}}"
           data-bv-notempty-message="{{_('验证码错误')}}"
           data-bv-stringLength-message="{{_('验证码错误')}}"required/>
</div>
<!--验证码区域-->

<!--发送验证码-->
<div id="send_code_div" class="form-group" hidden>
    <button id="send_code"  data-toggle="modal" data-target="#send_code_modal"  class="btn osr-btn btn-info">
        {{_('发送验证码')}}
    </button>
</div>
<div id="send_code_2_div" class="form-group">
    <button id="send_code_2" v-on:click="send_code()"  class="btn osr-btn btn-info">
        {{_('发送验证码')}}
    </button>
</div>
<!--模拟框-->
<div class="modal fade" id="send_code_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">{{_("发送验证码")}}</h4>
            </div>
            <div v-if="img_code_url" class="modal-body text-center" >
                <div class="form-group">
                  <input name="code" type="text" v-model="img_code" class="text-center form-control osr-input"
                   placeholder="{{_('图片验证码')}}"
                   data-bv-notempty-message="{{_('验证码错误')}}" required/>
                </div>
                <div class="form-group">
                    <img :src="img_code_url" alt="Code Img">
                    <i v-on:click="get_imgcode()" class="fa fa-refresh"></i>
                </div>
            </div>

            <div class="modal-footer">
                <button class="btn btn-info osr-btn" type="button" data-dismiss="modal" aria-hidden="true"> {{_("关闭")}}</button>
                <button class="btn btn-success osr-btn" v-on:click="send_code()" type="button" aria-hidden="true"> {{_("发送验证码")}}</button>
            </div>
        </div>
    </div>
</div>
<!--模拟框-->
<!--发送验证码//-->
 <script>

   function get_imgcode(){

        var result = osrHttp("GET","/api/vercode/image", {}, args={not_prompt:true});
        result.then(function (r) {
            if(r.data.msg_type=="s"){
                if(r.data.code){
                    vue.img_code_url = r.data.code.url;
                    vue.img_code_url_obj = r.data.code.img_url_obj;
                }
            }
        })
   }

   function send_code(){

        d = {
            account:vue.email,
            account_type:"email",
            code:vue.img_code,
            code_url_obj:JSON.stringify(vue.img_code_url_obj),

        }
        if(vue.send_code_to_exist_account){
            d["exist_account"] = 1;
        }
        // 提交数据
        var result = osrHttp("POST","/api/vercode/send", d);
        result.then(function (r) {
            if(r.data.msg_type=="s"){
                //发送成功
                $("#send_code_div").hide();
                $("#send_code_2_div").show();

                //验证码发送成功, 关闭已经打开的模态框(如果已经打开)
                $('#send_code_modal').modal('hide');

                $("#send_code_2").attr("disabled","disabled");
                var n = 60;
                window.setInterval(
                    function(){
                        if(!n){
                            $("#send_code_2").attr("disabled",false);
                            $('#send_code_2').text("{{_('发送验证码')}}")
                            return;
                        };
                        $('#send_code_2').text(n+"s{{_('后重发')}}")
                        n -= 1;
                    },
                1000);

                }
         }).catch(function (r) {

                if(r.data.code){
                    //图片验证码错误, 需要输入图片验证码 打开模态框,
                    $('#send_code_modal').modal('show');
                    vue.img_code_url = r.data.code.url;
                    vue.img_code_url_obj = r.data.code.img_url_obj;
                    $("#send_code_div").show();
                    $("#send_code_2_div").hide();
                }
         });

    }

 </script>